var cfg = require('cfg');

var driverOrder = {};
var userOrder = {};
var adminOrder = {};

var initUser = function (user) {
  wx.reLaunch({
    url: '/pages/customer/customer'
  })
}

var initDriver = function (user) {
//TODO 加载最新的订单
  wx.reLaunch({
    url: '/pages/driverOrderLine/OrderLine'
  })

}

var initAdmin = function (user) {
  //TODO 检查本地是否有未分配的订单
}

var initSystem = function(user) {
  //根据用户角色来初始化信息
  console.log('>>>>>>>>>>>>>>>>>>>>初始化系统信息' + user.initUser);
  if (user.adminRole) {
    initAdmin(user);
  } else if (user.initDriver) {
    initDriver(user);
  } else if (user.initUser) {
    initUser(user);
  }

}


var word4Mp3Tran = function (openId, typeMp3) {
  let innerAudioContext = wx.createInnerAudioContext();
  innerAudioContext.autoplay = true;
  innerAudioContext.src = cfg.host + cfg.djurl.word2Mp3 + '?openId=' + openId + '&typeMp3=' + typeMp3;
}

var word4Mp3Tran2 = function (openId, typeMp3, orderId) {
  let innerAudioContext = wx.createInnerAudioContext();
  innerAudioContext.autoplay = true;
  innerAudioContext.src = cfg.host + cfg.djurl.word2Mp3 + '?openId=' + openId + '&typeMp3=' + typeMp3 + '&orderId=' + orderId;
}


module.exports = {
  driverOrder,
  userOrder,
  adminOrder,
  initSystem, 
  word4Mp3Tran,
  word4Mp3Tran2
}